package com.dingtalk.h5app.quickstart.domain.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.Objects;

@JsonIgnoreProperties(ignoreUnknown = true)
@Getter
@Setter
//@ToString
@Entity
public class Cellwidget {
    @Id
    @GenericGenerator(name="idGenerator", strategy="uuid") //这个是hibernate的注解/生成32位UUID
    @GeneratedValue(generator="idGenerator")
    private String id;
    private String name;
    private String label;
    private String type;
    private String value;
    @ManyToOne(cascade = CascadeType.ALL,optional = false,fetch = FetchType.LAZY)
    @JoinColumn(name = "fid", referencedColumnName = "id"/*,insertable =false,updatable = false*/)
    //name是本表的外键名称，referencedColumnName是参考的关联表中的字段名称，如果没有，默认是数据库的主键字段
    @JsonIgnoreProperties("cellwidgetList")
    @ToString.Exclude//https://www.jianshu.com/p/778cc2711bd0
    private Widget widget;
    /*@Transient
    public void setWidgeRelation(Widget arg) {
        if(widget!=null) widget.getCellwidgetList().remove(this);
        widget=arg;
        if(widget!=null) widget.getCellwidgetList().add(this);
    }*/

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Cellwidget that = (Cellwidget) o;
        return Objects.equals(name, that.name);
    }

    @Override
    public int hashCode() {

        return Objects.hash(name);
    }
}
